package cn.csc.module.shop.api.user;

import cn.csc.framework.common.pojo.CommonResult;
import cn.csc.framework.security.core.LoginUser;
import cn.csc.framework.security.core.util.SecurityFrameworkUtils;
import cn.csc.module.shop.api.user.dto.ShopUserRespDTO;
import cn.csc.module.shop.convert.user.ShopUserConvert;
import cn.csc.module.shop.service.user.ShopUserService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigInteger;

/**
 * 店铺用户 API 实现类
 * @author liuchuang
 * @version 1.0
 * @date 2024/2/19 11:48
 * @modify
 */
@RestController // 提供 RESTful API 接口，给 Feign 调用
@Validated
public class ShopUserApiImpl implements ShopUserApi{

    @Resource
    private ShopUserService shopUserService;

    @Override
    public CommonResult<ShopUserRespDTO> getShopUser() {
        // 获取当前登录用户
        LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
        return CommonResult.success(ShopUserConvert.INSTANCE.convert2(shopUserService.getByUserId(BigInteger.valueOf(loginUser.getId()))) );
    }
}
